﻿$(document).ready(function () {
    //tab切换
    Tab("#tablist", "#tabdiv", 4, "on");
    TabMouseover("#tablist", "#tabdiv", 4, "on");
    $('.center_content').delegate('[data-type="AppDownLoadP"]', 'mouseover', function (o) {
        $(this).parent().find('[data-type="AppDownLoad"]').eq(0).show();
    });
    $('.center_content').delegate('[data-type="AppDownLoadP"]', 'mouseleave', function (o) {
        $(this).parent().find('[data-type="AppDownLoad"]').eq(0).hide();
    });
});
function btnSearch(obj) {
    $("#datetype").val(obj);
    $("#form1").submit();
}
function AbandonSOBySoID(soid) {
    var msg = "您确定要作废该订单吗？";
    if (confirm(msg) == true) {
        $.ajax({
            type: 'POST',
            url: '/UserHome/AbandonSO',
            data: "soid=" + soid,
            cache: false,
            dataType: "application/JSON; charset=utf-8",
            success: function (msg) {
                if (AjaxValidate(msg)) {
                    if (msg == "订单已作废") {
                        $("#IsCancel").html(1);
                        alert('订单已作废', 1);
                        $("#form1").submit();
                    } else if (msg == "非法的操作,-1") {
                        alert("非法的操作");
                    } else if (msg == "取消订单失败，请联系客服") {
                        alert("作废订单失败，请联系客服");
                    } else {
                        alert(msg);
                    }
                }
            }
        })
    }
    else {
        return false;
    }
}
//点击查询
function Tan_order(id) {
    var tagId = "#POrder" + id;
    $(tagId).removeClass("none");
}
//点击关闭
function Cang_order(id) {
    var tagId = "#POrder" + id;
    $(tagId).addClass("none");
}
var selfId = "";
function GetData(datatype, id) {
    var showSite = 0;
    if ($("#chkShowCurrent").attr("checked") == true) {
        showSite = window.Cookies("WebSiteSysNo").val();
    }

    selfId = datatype + "_" + id + "_" + showSite;
    setTimeout(function () {
        if (selfId == datatype + "_" + id + "_" + showSite) {
            var html = "<div>&nbsp;<img src=\"/Content/images/loading.gif\" /> 正在请求数据,请稍候......</div>";
            var divid = "";

            if (datatype == 1) {
                divid = "#tabdiv1";
            }
            else if (datatype == 2) {
                divid = "#tabdiv2";
            }
            else if (datatype == 0) {
                divid = "#tabdiv3";
            }
            else if (datatype == 4) {
                divid = "#tabdiv4";
            }
            else {
                divid = "#tabdiv1";
            }
            id = id + 1;
            $(divid).prepend(html);
            $.ajax({
                type: "POST",
                url: "/UserHome/GetOrderList?type=" + datatype + "&page=" + id + "&showsite=" + showSite,
                cache: false,
                success: function (data) {
                    if (AjaxValidate(data)) {
                        $(divid).html(data);
                    }
                    lazyLoad.Run();
                }
            })
        }
    }, 300);
}
var reflash = false;
var currentLoad = false;
function ReLoad(type) {
    if (type == 1) {
        if ($("#tabdiv1").html().length <= 100 || reflash) {
            GetData(1, 0);
        }
    }
    else if (type == 2) {
        if ($("#tabdiv2").html().length <= 100 || reflash) {
            GetData(2, 0);
        }
    }
    else if (type == 3) {
        if ($("#tabdiv3").html() == null || $("#tabdiv3").html().length <= 100 || reflash) {
            GetData(0, 0);
        }
        else {
            if ($("#IsCancel").html() == 1 || reflash) {
                GetData(0, 0);
                $("#IsCancel").html(0);
            }
        }
    }
    else if (type == 4) {
        if ($("#tabdiv2").html().length <= 100 || reflash) {
            GetData(4, 0);
        }

    }
}

function showsiteorder() {
    reflash = true;
    if ($("#id_3").hasClass("on"))
        ReLoad(3);
    else if ($("#id_2").hasClass("on"))
        ReLoad(2);
    else if ($("#id_4").hasClass("on"))
        ReLoad(4);
    else
        ReLoad(1);
    reflash = false;
}

function HidenTrackDiv(sysno) {
    $("#orderTrackInfo_" + sysno).removeClass('trackinghover');
}
function GetOrderTrack(sysno) {
    $(".trackmw").each(function (i) {
        var id = $(this).attr("id");
        if (id != "orderTrackInfo_" + sysno) {
            $(this).removeClass('trackinghover');
        } else {
            if (!$(this).hasClass("trackinghover")) {
                $("#orderTrackInfo_" + sysno).addClass('trackinghover');
            }
        }
    });
    // 这个地方要注意下
    if ($.trim($("#orderTrackInfo_" + sysno).html()).length > 25) {
        $("#orderTrackInfo_" + sysno).addClass('trackinghover');
        return;
    } else {
        $.ajax({
            type: "GET",
            url: "/UserHome/OrderTrack?SysNO=" + sysno,
            cache: false,
            success: function (date) {
                if (AjaxValidate(date)) {
                    index = 1;
                    $("#orderTrackInfo_" + sysno).html(date);
                }
            }
        })
    }
}
function AbandonSOBySoID(soid, datetype, abdType) {
    if (!abdType) {
        abdType = 0;
    }
    var msg = "您确定要作废该订单吗？";
    if (confirm(msg) == true) {
        $.ajax({
            type: 'POST',
            url: '/UserHome/AbandonSO',
            cache: false,
            data: "soid=" + soid + "&type=" + abdType,
            success: function (msg) {
                if (AjaxValidate(msg)) {
                    if (msg == "订单已作废") {
                        alert('订单已作废', 1);
                        $("#IsCancel").html(1);
                        GetData(datetype, 0)
                    } else if (msg == "非法的操作,-1") {
                        alert("非法的操作");
                    } else if (msg == "取消订单失败，请联系客服") {
                        alert("作废订单失败，请联系客服");
                    } else {
                        alert(msg);
                    }
                }
            }
        })
    }
    else {
        return false;
    }
}

function gotoMyCommentsPage(soSysNo) {
    window.location.href = "/UserHome/Mycomments?SoSysNo=" + soSysNo;
    return false;
}

function Pay(page, sysno, soid, type) {
    var osid = "0";
    if (!type) { type = ""; }
    if (page == "ChinaUnionPay") {
    } else if (page == 'Alipay') {
    } else if (page == 'ICBCPay') {
    } else if (page == 'TenPay') {
    } else if (page == 'OnlinePay' && type == '&type=os') {
        osid = sysno;
        sysno = 0;
        soid = "";
    }
    //goShoppingFromCheck(4);
    window.open("/Shopping/" + page + "?id=" + sysno + "&sono=" + soid + "&g=1" + type + "&osid=" + osid, "_blank");
    return false;
}

function AbandonGC(id, datatype) {
    //if (!confirm("您确定要作废该订单吗？")) return;
    $.ajax({
        type: 'POST',
        url: '/userhome/AbandonGC',
        cache: false,
        data: { id: id },
        success: function (data) {
            if (AjaxValidate(data)) {
                if (data.Status == 1) {
                    GetData(datatype, 0);
                    alert(data.Msg, 1)
                } else {
                    alert(data.Msg);
                }
            }
        }
    })
}

function GoMergePay(GPSysNO, TotalAmt) {
    var mergeUrl = "";
    $.ajax({
        type: 'POST',
        url: "/Shopping/GetMergePay?GPSysNO=" + GPSysNO + "&TotalAmt=" + TotalAmt,
        cache: false,
        async: false,
        beforeSend: function () {
            Loadding("show");
        },
        success: function (data) {
            if (AjaxValidate(data)) {
                Loadding("hide");
                if (data.states == 1) {
                    var sysno = data.MergePaySysNo;
                    mergeUrl = "/Shopping/MergePay?SysNo=" + sysno;
                    return false;
                } else if (data.states == 2) {
                    var sysno = data.SOSysNo;
                    var sono = data.SONO;
                    mergeUrl = "/Shopping/OnlinePay?id=" + sysno + "&sono=" + sono;
                    return false;
                } else {
                    alert(data.Msg);
                }
            }
        }
    });
    window.open(mergeUrl);
    return false;
}


function CancelSO(soid, datetype, abdType) {
    if (!abdType) {
        abdType = 0;
    }
    var msg = "您确定要取消该订单吗？";
    //if (confirm(msg) == true) {
    $.ajax({
        type: 'POST',
        url: '/UserHome/CancelSO',
        cache: false,
        data: "soid=" + soid + "&type=" + abdType,
        success: function (msg) {
            if (AjaxValidate(msg)) {
                if (msg == "订单已取消") {
                    alert('订单已取消', 1);
                    $("#IsCancel").html(1);
                    GetData(datetype, 0)
                } else if (msg == "非法的操作,-1") {
                    alert("非法的操作");
                } else if (msg == "取消订单失败，请联系客服") {
                    alert("取消订单失败，请联系客服");
                } else {
                    alert(msg);
                }
            }
        }
    });
    //}
    //else {
    //    return false;
    //}
}



var intervalID;
var curLi;
var index = 1;
$(document).ready(function () {
    $(".cutover_nav li ").live("mouseenter", function () {
        curLi = $(this);
        intervalID = setInterval(onMouseOver, 750);//鼠标移入的时候有一定的延时才会切换到所在项，防止用户不经意的操作 
    });
    function onMouseOver() {
        Show();
    }
    $(".cutover_nav li").live("mouseleave", function () {
        clearInterval(intervalID);
    });

    $(".cutover_nav li").live("click", function () {//鼠标点击也可以切换  
        Show();
    });

});
function Show() {
    clearInterval(intervalID);
    $(".trackinghover").find(".cur-sub-con").removeClass("cur-sub-con");
    //alert($(".trackinghover").find(".sub-con").eq($(".cutover_nav li ").index($(".cur"))))
    $(".trackinghover").find(".sub-con").eq($(".trackinghover").find(".cutover_nav li ").index(curLi)).addClass("cur-sub-con");
    $(".trackinghover").find(".cur").removeClass("cur");
    curLi.addClass("cur");
}
function move(type, id) {
    var showcount = 5;
    var leng = $('#ul_' + id + ' li').length;
    if (leng <= showcount)
        return;
    else {
        if ((type == -1 && index == 1) || (type == 1 && index == (leng - showcount + 1)))
        { return; }
        else
        {
            index += type;
            var endindex = index + showcount - 1;
            for (var i = 1; i <= leng; i++) {
                if (i >= index && i <= endindex) {
                    $('#ul_' + id + ' li').eq(i - 1).removeClass("none").addClass("block");

                }
                else {
                    $('#ul_' + id + ' li').eq(i - 1).removeClass("block").addClass("none");
                }
            }
        }
    }
}




function DeleteSOBySoID(soid, datetype, abdType) {
    if (!abdType) {
        abdType = 0;
    }
    var msg = "订单删除后将无法找回，确定要删除订单吗？";
    if (confirm(msg) == true) {
        $.ajax({
            type: 'POST',
            url: '/UserHome/DeleteSO',
            cache: false,
            data: "soid=" + soid + "&type=" + abdType,
            success: function (msg) {
                if (AjaxValidate(msg)) {
                    if (msg == "订单已删除") {
                        alert('订单已删除', 1);
                        $("#IsCancel").html(1);
                        GetData(datetype, 0)
                    } else if (msg == "非法的操作,-1") {
                        alert("非法的操作");
                    } else if (msg == "删除订单失败，请联系客服") {
                        alert("删除订单失败，请联系客服");
                    } else {
                        alert(msg);
                    }
                }
            }
        })
    }
    else {
        return;
    }
}



function DeleteGC(id, datatype) {

    if (!confirm("您确定要作删除订单吗？")) return;
    $.ajax({
        type: 'POST',
        url: '/userhome/DeleteGC',
        cache: false,
        data: { id: id },
        success: function (data) {
            if (AjaxValidate(data)) {
                if (data.Status == 1) {
                    GetData(datatype, 0);
                    alert(data.Msg, 1)
                } else {
                    alert(data.Msg);
                }
            }
        }
    })
}


function UpdateOrder(url, isPay) {
   
    if ( isPay  && new Date().getHours() >= 17) {
        ShowBack();
        var cartPopUp = $("#cart_pop_Up");
        cartPopUp.show();
        $("#btnSubmit").attr("href", url);
    } else {
        window.location.href = url;
    }

}
function hideCanceUp() {
    $("#cart_pop_Up").hide();
    HideBack();
}

function CancelOrderDone() {
    var cancelType = $("#hidden_CancelType").val();
    var soid = $("#hidden_SOID").val();
    var dataType = $("#hidden_DataType").val();
    if (1 == cancelType) {
        CancelSO(soid, dataType);
        hideCancelSO();
    }
    else if (2 == cancelType) {
        AbandonGC(soid, dataType);
        hideCancelSO();
    }
};
function showCancelSO(payStatus, orderSysNo, soid, dataType, num, israpidorder) {
    $("#payMsg").hide();
    $("#editSO").hide();

    if (israpidorder === 1) {
        $("#editSO").hide();
    } else {
        $("#editSO").show();
    }
    if (num == 3) {
        if (confirm("确定取消此订单吗？")) {
            CancelSO(soid, dataType);
            return;
        } else {
            return;
        }
    }
    ShowBack();
    $("#cart_pop_change").show();
    var updateUrl = "/order/NewUpdateOrder/" + orderSysNo;

    $("#editSO").attr("href", updateUrl);

    if (payStatus === 1) {
        $("#payMsg").show();
        $("#editSO").attr("href", "javascript:hideCancelSO();");
        $("#editSO").text("返回");
    } else {
        $("#payMsg").hide();
        $("#editSO").text("去修改订单");
    }


    $("#hidden_CancelType").val(1);
    $("#hidden_SOID").val(soid);
    $("#hidden_DataType").val(dataType);
}

function hideCancelSO() {
    $("#cart_pop_change").hide();
    HideBack();
}